package logic.SysPerson

import cn.ibizlab.util.domain.EntityBase
import cn.ibizlab.util.helper.RuleUtils
import cn.ibizlab.util.security.AuthenticationUser
import cn.ibizlab.util.security.SpringContextHolder
import cn.ibizlab.core.ad.domain.SysPerson
import cn.ibizlab.core.ad.service.SysPersonService
import cn.ibizlab.core.ad.domain.SysMember
import cn.ibizlab.core.ad.service.SysMemberService
import cn.ibizlab.core.ad.domain.SysOrganizationalRole
import cn.ibizlab.core.ad.service.SysOrganizationalRoleService
import com.alibaba.fastjson.JSONObject
import org.springframework.util.ObjectUtils

/**
 *  初始化当前选中用户组成员
 */
class InitGroupMember {

    //当前用户
    def curuser = AuthenticationUser.getAuthenticationUser()
    //传入变量
    def _default
    def _list = new EntityBase()
    //member
    def _member = new SysMember()
    //orggroup
    def _orggroup = new SysOrganizationalRole()
    //返回参数
    def _return

    def execute(arg) {
        println 'running....'
        _default = arg
        
        
        _return = arg
        begin()
        println 'running end....'
        return _return
    }

    //开始
    def begin() {
    
        //parent为用户组
        if(((RuleUtils.test(_default.get('srfparentdename'), 'RIGHTLIKE', 'organizational_role')) && (RuleUtils.test(_default.get('srfparentkey'), 'ISNOTNULL', 'null')))) {
            prepareparam1()
        }
        //连接名称
        if((((RuleUtils.test(_default.get('srfparentdename'), 'NOTEQ', 'organizational_role')) || (RuleUtils.test(_default.get('srfparentkey'), 'ISNULL', 'null'))))) {
            debugparam2()
        }
    }

    //准备参数
    def prepareparam1() {
        _orggroup.set("id", _default.get("srfparentkey"))

        if(true) {
            deaction1()
        }
    }

    //查询用户组
    def deaction1() {
        SpringContextHolder.getBean(SysOrganizationalRoleService.class).get(_orggroup)

        if(true) {
            prepareparam2()
        }
    }

    //准备参数
    def prepareparam2() {
        _member.set("sort", "1")
        _member.set("organization_id", _orggroup.get("organization_id"))
        _member.set("organization_number", _orggroup.get("organization_number"))
        _member.set("organization_name", _orggroup.get("organization_name"))
        _member.set("dc", _orggroup.get("dc"))
        _member.set("department_id", _orggroup.get("department_id"))
        _member.set("department_name", _orggroup.get("department_name"))
        _member.set("department_number", _orggroup.get("department_number"))
        _member.set("organizational_role_id", _orggroup.get("id"))
        _member.set("organizational_role_name", _orggroup.get("name"))
        _list.set("", _member.get(""))
        _default.set("member_of", _list.get(""))
        _default.set("organization_id", _orggroup.get("organization_id"))
        _default.set("organization_number", _orggroup.get("organization_number"))
        _default.set("organization_name", _orggroup.get("organization_name"))

        if(true) {
            debugparam2()
        }
    }

    //结束调试参数
    def debugparam2() {
        println _default
        if(true) {
            end1()
        }
    }

    //结束
    def end1() {
        _return = _default

    }

}
